<!--区域管理-->
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="utf-8">
	<title>供应商维护</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="resources/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="resources/css/public.css" media="all" />
	<link rel="stylesheet" href="resources/layui_ext/dtree/dtree.css">
    <link rel="stylesheet" href="resources/layui_ext/dtree/font/dtreefont.css">
</head>
<body class="childrenBody">
<!--查询条件-->
<div class="layui-collapse" id="search">
    <blockquote class="layui-elem-quote quoteBox">
    <form class="layui-form" id="providerTable" lay-filter="providerTable">
	    <div class="layui-form-item layui-row">
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">供货商名称</label>
                	<div class="layui-input-block">
                	    <input type="hidden" name="id">
                	    <input type="text" name="providerName" class="layui-input searchVal"/>
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-center">
                <div class="layui-input-block">
                   <button type="submit" class="layui-btn" lay-submit="" lay-filter="sub">查询</button>
                </div>
            </div>
        </div>
	</form>
	</blockquote>
</div>
<!--数据表格-->
<div>
    <table class="layui-hide" id="providerShowTable" lay-filter="providerShowTable"></table>
    <div id="toolBars" style="display: none">
        <button type="button" lay-event="add" class="layui-btn layui-btn-sm"><span class="layui-icon layui-icon-add-1"></span>添加</button>
    </div>
    <div id="rowBars" style="display: none">
        <button type="button" lay-event="show" class="layui-btn layui-btn-sm layui-btn-warm"><span class="layui-icon layui-icon-search"></span>查看</button>
        <button type="button" lay-event="update" class="layui-btn layui-btn-sm layui-bg-green"><span class="layui-icon layui-icon-edit"></span>修改</button>
        <button type="button" lay-event="delete" class="layui-btn layui-btn-sm layui-btn-danger"><span class="layui-icon layui-icon-delete"></span>删除</button>
    </div>
</div>
<!--添加修改弹出层-->
<div id="addOrUpdate" style="display: none">
    <form class="layui-form" id="addOrUpdateTable" lay-filter="addOrUpdateTable">
	    <div class="layui-form-item layui-row">
	        <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">供应商名称</label>
                	<div class="layui-input-block">
                		<input type="text" name="providerName" lay-verify="required" class="layui-input searchVal"  />
                	</div>
                </div>
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">企业类别</label>
                	<div class="layui-input-block">
                		<input type="text" name="providerCategory" lay-verify="required" class="layui-input searchVal"  />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">许可证</label>
                	<div class="layui-input-block">
                		<input type="text" lay-verify="required" name="licence" class="layui-input searchVal"/>
                	</div>
                </div>
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">网址</label>
                	<div class="layui-input-block">
                		<input type="text" lay-verify="url" name="url" class="layui-input searchVal"  />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">许可证到期时间</label>
                	<div class="layui-input-block">
                	    <input type="hidden" name="id">
                	    <input type="text" lay-verify="required" readonly id="licenceDeadline" name="licenceDeadline" class="layui-input searchVal"/>
                	</div>
                </div>
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">企业联系人</label>
                	<div class="layui-input-block">
                		<input type="text" name="providerLinkman" lay-verify="required" class="layui-input searchVal"  />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">企业联系电话</label>
                	<div class="layui-input-block">
                	    <input type="hidden" name="id">
                		<input type="text" lay-verify="required|phone" name="providerPhone" class="layui-input searchVal"  />
                	</div>
                </div>
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">营业范围</label>
                	<div class="layui-input-block">
                		<input type="text" name="businessScope" lay-verify="required" class="layui-input searchVal"  />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">注册地址</label>
                	<div class="layui-input-block">
                		<input type="text" name="registeredAddress" lay-verify="required" class="layui-input searchVal"  />
                	</div>
                </div>
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">联系地址</label>
                	<div class="layui-input-block">
                		<input type="text" name="contactAddress" lay-verify="required" class="layui-input searchVal"  />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">邮政编码</label>
                	<div class="layui-input-block">
                		<input type="text" name="postalCode" lay-verify="number" class="layui-input searchVal"  />
                	</div>
                </div>
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">总资产(万元)</label>
                	<div class="layui-input-block">
                		<input type="text" name="totalAssets" lay-verify="number" class="layui-input searchVal"  />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">企业传真</label>
                	<div class="layui-input-block">
                		<input type="text" name="providerFax" class="layui-input searchVal"  />
                	</div>
                </div>
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">法人代表</label>
                	<div class="layui-input-block">
                		<input type="text" name="corporateRepresentative" class="layui-input searchVal"  />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">法人身份证</label>
                	<div class="layui-input-block">
                		<input type="text" name="corporataNumber" lay-verify="identity" class="layui-input searchVal"  />
                	</div>
                </div>
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">企业注册资金</label>
                	<div class="layui-input-block">
                		<input type="text" name="registeredCapital" lay-verify="number" class="layui-input searchVal"  />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">上年度销售金额(万元)</label>
                	<div class="layui-input-block">
                		<input type="text" name="annualSalesAmount"  lay-verify="number" class="layui-input searchVal"  />
                	</div>
                </div>
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">电子信箱</label>
                	<div class="layui-input-block">
                		<input type="text" lay-verify="email" name="email" class="layui-input searchVal"  />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row" id="hi">
                <div class="layui-block ">
                    <label class="layui-form-label">供货区域：</label>
                	<div class="layui-input-block">
                	    <input type="hidden" name="pid" id="pid" class="layui-input searchVal" />
                	    <ul id="pidTree" class="dtree" data-id="0"></ul>
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-center">
                <div class="layui-input-block">
                   <button type="submit" class="layui-btn" lay-submit="" lay-filter="submit">提交</button>
                </div>
            </div>
        </div>
  	</form>
</div>
<!--查看弹出层-->
<div id="show" style="display: none">
    <form class="layui-form" id="showTable" lay-filter="showTable">
	    <div class="layui-form-item layui-row">
	        <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">供应商名称</label>
                	<div class="layui-input-block">
                		<input type="text" name="providerName" readonly lay-verify="required" id="providerName" class="layui-input searchVal"  />
                	</div>
                </div>
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">企业类别</label>
                	<div class="layui-input-block">
                		<input type="text" name="providerCategory" readonly lay-verify="required" class="layui-input searchVal"  />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">许可证</label>
                	<div class="layui-input-block">
                		<input type="text" lay-verify="required" name="licence" readonly class="layui-input searchVal"/>
                	</div>
                </div>
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">网址</label>
                	<div class="layui-input-block">
                		<input type="text" lay-verify="url" readonly name="url" class="layui-input searchVal"  />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">许可证到期时间</label>
                	<div class="layui-input-block">
                	    <input type="hidden" name="id">
                	    <input type="text" lay-verify="required" readonly name="licenceDeadline" class="layui-input searchVal"/>
                	</div>
                </div>
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">企业联系人</label>
                	<div class="layui-input-block">
                		<input type="text" name="providerLinkman" readonly lay-verify="required" class="layui-input searchVal"  />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">企业联系电话</label>
                	<div class="layui-input-block">
                	    <input type="hidden" name="id">
                		<input type="text" lay-verify="required|phone" readonly name="providerPhone" class="layui-input searchVal"  />
                	</div>
                </div>
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">营业范围</label>
                	<div class="layui-input-block">
                		<input type="text" name="businessScope" readonly lay-verify="required" class="layui-input searchVal"  />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">注册地址</label>
                	<div class="layui-input-block">
                		<input type="text" name="registeredAddress" readonly lay-verify="required" class="layui-input searchVal"  />
                	</div>
                </div>
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">联系地址</label>
                	<div class="layui-input-block">
                		<input type="text" name="contactAddress" lay-verify="required" class="layui-input searchVal"  />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">邮政编码</label>
                	<div class="layui-input-block">
                		<input type="text" name="postalCode" readonly class="layui-input searchVal"  />
                	</div>
                </div>
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">总资产(万元)</label>
                	<div class="layui-input-block">
                		<input type="text" name="totalAssets" readonly class="layui-input searchVal"  />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">企业传真</label>
                	<div class="layui-input-block">
                		<input type="text" name="providerFax" readonly class="layui-input searchVal"  />
                	</div>
                </div>
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">法人代表</label>
                	<div class="layui-input-block">
                		<input type="text" name="corporateRepresentative" readonly class="layui-input searchVal"  />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">法人身份证</label>
                	<div class="layui-input-block">
                		<input type="text" name="corporataNumber" readonly class="layui-input searchVal"  />
                	</div>
                </div>
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">企业注册资金</label>
                	<div class="layui-input-block">
                		<input type="text" name="registeredCapital" readonly class="layui-input searchVal"  />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">上年度销售金额(万元)</label>
                	<div class="layui-input-block">
                		<input type="text" name="annualSalesAmount" readonly class="layui-input searchVal"  />
                	</div>
                </div>
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">电子信箱</label>
                	<div class="layui-input-block">
                		<input type="text" lay-verify="email" readonly name="email" class="layui-input searchVal"  />
                	</div>
                </div>
            </div>
        </div>
  	</form>
</div>
<script type="text/javascript" src="resources/layui/layui.js"></script>
<script type="text/javascript" src="/resources/layui_ext/dtree/dtree.js"></script>
<script>
    layui.extend({
                        dtree: '/resources/layui_ext/dtree/dtree'   // {/}的意思即代表采用自有路径，即不跟随 base 路径
                      }).use(['form','laydate','element','layer','jquery','table'],function(){
        var form = layui.form;
        var layer = layui.layer;
        var $ = layui.jquery;
        var table = layui.table;
        var dtree = layui.dtree;
        var laydate = layui.laydate;
        laydate.render({
            elem:'#licenceDeadline'
            ,type: 'datetime'
        })
        //加载下拉树
        var pidTree = dtree.renderSelect({
            elem: "#pidTree",
            width: "100%", // 指定树的宽度
            url: "/area/loadTree",
            checkbar: true,
            checkbarType: "all", // 默认就是all，其他的值为： no-all  p-casc   self  only
            dataStyle: "layuiStyle",  //使用layui风格的数据格式
            dataFormat: "list",  //配置data的风格为list
            response:{message:"msg",statusCode:0}  //修改response中返回数据的定义
        });
        //监听下拉树的单击方法
        dtree.on("node('pidTree')" ,function(obj){
            $("#pid").val(obj.param.nodeId);
            console.log(obj);
            //$("#").val(obj.param.nodeId==1?"村":obj.param.nodeId==0?"乡镇":"市");
        });
        var tableIns = table.render({
            elem:"#providerShowTable",
            url:"/provider/loadProvider",
            toolbar:"#toolBars",
            page:true,
            height:'full',
            cols:[
                [
                    {type:'checkbox',fixed:'center'}
                    ,{field:'id', title:'ID',  fixed: 'left', unresize: true,width:'80' ,sort: true,align:'center'}
                    ,{field:'providerName', title:'供应商名称',align:'center',width:'180'}
                    ,{field:'providerCategory', title:'企业类别',align:'center',width:'150'}
                    ,{field:'licence', title:'许可证',align:'center',width:'150'}
                    ,{field:'licenceDeadline', title:'许可证到期时间',align:'center',width:'150'}
                    ,{field:'providerLinkman', title:'企业联系人',align:'center',width:'150'}
                    ,{field:'providerPhone', title:'企业联系电话',align:'center',width:'150'}
                    ,{field:'businessScope', title:'营业范围',align:'center',width:'150'}
                    ,{field:'registeredAddress', title:'注册地址',align:'center',width:'180'}
                    ,{field:'contactAddress', title:'联系地址',align:'center',width:'150'}
                    ,{field:'postalCode', title:'邮政编码',align:'center',width:'150'}
                    ,{field:'totalAssets', title:'总资产',align:'center',width:'150'}
                    ,{field:'providerFax', title:'企业传真',align:'center',width:'150'}
                    ,{field:'corporateRepresentative', title:'法人代表',align:'center',width:'150'}
                    ,{field:'corporataNumber', title:'法人身份证',align:'center',width:'150'}
                    ,{field:'registeredCapital', title:'企业注册资金',align:'center',width:'150'}
                    ,{field:'annualSalesAmount', title:'上年度销售金额',align:'center',width:'150'}
                    ,{field:'email', title:'电子信箱',align:'center',width:'150'}
                    ,{field:'url', title:'网址',align:'center',width:'150'}
                    ,{fixed: 'right', title:'操作', toolbar: '#rowBars',width:260}
                ]
            ]
        });
        //模糊表单提交
        form.on("submit(sub)",function(data) {
            tableIns.reload({
                where:data.field
            })
            return false;
        })

        var mainIns;
        var url;
        //监听头部工具栏事件
        table.on('toolbar(providerShowTable)',function(obj) {
            switch (obj.event) {
                case 'add':
                    openAdd();
            }
        });
        //监听行工具栏事件
        table.on('tool(providerShowTable)',function(obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'show':
                    openShow(data);
                    break;
                case 'update':
                    openUpdate(data);
                    break;
                case 'delete':
                    openDelete(data);
            }
        });
        //提交表单
        form.on('submit(submit)',function() {
            var params = $("#addOrUpdateTable").serialize();
            $.post(url,params,function(data) {
                //提示信息
                layer.msg(data.msg);
                //关闭弹出层
                layer.close(mainIns);
                //重新渲染table
                tableIns.reload();
            })
            return false;
        });
        //关闭弹出层
        form.on('submit(close)',function() {
            var params = $("#addOrUpdateTable").serialize();
            $.post(url,params,function(data) {
                //关闭弹出层
                layer.close(mainIns);
            })
            return false;
        });
        //打开添加弹出层
        function openAdd() {
            mainIns = layer.open({
                type:1,
                content:$("#addOrUpdate"),
                area:['900px','480px'],
                title:"添加用户",
                success:function(layero,index) {
                    //更改url
                    url = "/provider/add";
                    $("#addOrUpdateTable")[0].reset();
                    $("#hi").show();
                }
            })
        }
        //打开修改弹出层
        function openUpdate(data) {
            url = "/provider/updateProvider";
            mainIns = layer.open({
                type:1,
                content:$("#addOrUpdate"),
                area:['800px','480px'],
                title:"修改用户",
                success:function(index) {
                    form.val("addOrUpdateTable",data);
                    $("#typeShow").val(data.type);
                    $("#hi").hide();
                }
            })
        }

        //打开查看弹出层
        function openShow(data) {
            mainIns = layer.open({
                type:1,
                content:$("#show"),
                area:['800px','480px'],
                title:"查看用户",
                success:function(index) {
                    console.log(data);
                    form.val("showTable",data);
                    $("#typeShow").val(data.type==1?"局":"院");
                }
            })
        }
        //打开删除弹出层
        function openDelete(data) {
            mainIns = layer.confirm('您真的要删除吗？', {
                btn: ['删除','取消'] //按钮
            }, function(){
                $.post("/provider/delete",{id:data.id},function(res) {
                    layer.msg(res.msg);
                    tableIns.reload();
                })
            })
        }
    })
</script>
</body>
</html>